package engine.network.tests;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;

import engine.network.hostSide.enums.RoleRequest;
import engine.network.hostSide.enums.SpectReq;

public class Spectator {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		BufferedReader in = 
			new BufferedReader(new InputStreamReader(System.in));
		System.out.println("please give us the server URL");
		try {
			String url = in.readLine();
			Socket s = new Socket(url, 4462);
			PrintWriter socket_out = 
				new PrintWriter(s.getOutputStream());
			BufferedReader socket_in = 
				new BufferedReader(
						new InputStreamReader(s.getInputStream()));
			socket_out.println(RoleRequest.SPECTATOR.label());
			socket_out.flush();
			while(true){
				String str = socket_in.readLine();
				SpectReq req = SpectReq.factory(str);
				if(req == SpectReq.REFRESH){
					int leftX = Integer.parseInt(socket_in.readLine());
					int leftY = Integer.parseInt(socket_in.readLine());
					int rightX = Integer.parseInt(socket_in.readLine());
					int rightY = Integer.parseInt(socket_in.readLine());
					System.out.println("new coordonate :");
					System.out.println("\tleft :"+leftX+"x"+leftY
							+"\tright :"+rightX+"x"+rightY);
				}
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
